/* NinjaTrader Strategy of Strategy 1.4 Generated by StrategyQuant version 3.6.3 Generated at Sat Sep 06 21:09:00 GMT 2014 Tested on EURUSD_fhdb, D1, 01.11.2007 - 29.03.2013 Spread: 2.5, Slippage: 0.0, Min distance of stop from price: 5.0 */ #region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { /// /// Enter the description of your strategy here /// [Description("Enter the description of your strategy here")] public class Strategy14 : SQManagedStrategy { #region Variables // Wizard generated variables // User defined variables (add any user defined variables below) #endregion /// /// This method is used to configure the strategy and is called once before any strategy method is called. /// protected override void Initialize() { base.Initialize(); ReplacePendingOrders = true; ExitOnClose = false; MinimumPTSL = 30; MaximumPTSL = 300; PendingOrderValidOneBar = false; BarsRequired = 120; StrictStopPrices = true; LimitSignalsToRange = false; TimeRangeFrom = 0800; TimeRangeTo = 1600; MaxTradesPerDay = 0; // 0 means unlimited } /// /// Called on each bar update event (incoming tick) /// protected override void OnBarUpdate() { // ------------------------------------------ // STRATEGY MANAGEMENT // ------------------------------------------ if(Bars.FirstBarOfSession) tradesPerDay = 0; // Stop/Limit order expiration handling // Long -------- if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.Buy) { // Expiration if(sqGetPendingOrderBars(pendingEntryOrder) >= 30) { CancelOrder(pendingEntryOrder); } } // Short -------- if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.SellShort) { // Expiration if(sqGetPendingOrderBars(pendingEntryOrder) >= 30) { CancelOrder(pendingEntryOrder); } } // ------------------------------------------ // ENTRY RULES // ------------------------------------------ tradeEntered = false; if(sqCheckTimeWithinRange()) { // Long -------- if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) { bool LongEntryCondition = true; if(LongEntryCondition == true) { double price = roundPrice(WMA(4)[0] + (0.1) * (sqATR(94))); sqEnterLongStop(price); } } // Short -------- if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) { bool ShortEntryCondition = true; if(ShortEntryCondition == true) { double price = roundPrice(WMA(4)[0] + (-0.1) * (sqATR(94))); sqEnterShortStop(price); } } } // ------------------------------------------ // MANAGE TRADE & EXIT RULES // ------------------------------------------ if(tradeEntered) { // don't modify SL is new order was just placed return; } IOrder slOrder = sqGetStopLossOrder(); double priceLevel; // Long -------- // Exit After X Bars if(Position.MarketPosition == MarketPosition.Long) { if (BarsSinceEntry("Long") >= 10-1) { sqExitLong("LongExitAfterXBars"); } } // Stop trailing if(Position.MarketPosition == MarketPosition.Long) { priceLevel = roundPrice(sqParabolicSAR(0.02, 0.2, 0) + (0.8) * (sqATR(19))); if(priceLevel > 0) { if(slOrder == null) { sqSetLongSL(priceLevel); } else { if(slOrder.StopPrice == 0 || slOrder.StopPrice < priceLevel) { sqSetLongSL(priceLevel); } } } } // Short -------- if(Position.MarketPosition == MarketPosition.Short) { // Exit After X Bars if (BarsSinceEntry("Short") >= 10-1) { sqExitShort("ShortExitAfterXBars"); } } // Stop trailing if(Position.MarketPosition == MarketPosition.Short) { priceLevel = roundPrice(sqParabolicSAR(0.02, 0.2, 0) + (-0.8) * (sqATR(19))); if(priceLevel > 0) { if(slOrder == null) { sqSetShortSL(priceLevel); } else { if(slOrder.StopPrice == 0 || slOrder.StopPrice > priceLevel) { sqSetShortSL(priceLevel); } } } } } override protected void sqDefineStopLoss(int direction) { stopLoss.type = CalculationMode.Ticks; if(direction == 1) { // long stopLoss.value = 60; } else { // short stopLoss.value = 60; } } override protected void sqDefineProfitTarget(int direction) { profitTarget.type = CalculationMode.Ticks; if(direction == 1) { // long profitTarget.value = 0; } else { // short profitTarget.value = 0; } } #region Properties #endregion } }